## install.packages(c("haven", "tidyverse"))
library(haven)
library(tidyverse)

## Figure 1
ansa = read_stata("ansa.dta") %>%
  ggplot(., aes(x = month_id, y = mentions)) +
  geom_line()+
  geom_point() +
  geom_vline(xintercept = 387, 
             linetype = "dashed", 
             color = "black", size = 1) +
  geom_vline(xintercept = 410, 
             linetype = "dashed", 
             color = "gray", size = 1) +
  scale_x_continuous(breaks = seq(369, 420, 3), labels = c("Oct. 1990", "Jan. 1991", "Apr. 1991", "Jul. 1991", "Oct. 1991", 
                                                           "Jan. 1992", "Apr. 1992", "Jul. 1992", "Oct. 1992", 
                                                           "Jan. 1993", "Apr. 1993", "Jul. 1993", "Oct. 1993",
                                                           "Jan. 1994", "Apr. 1994", "Jul. 1994", "Oct. 1994",
                                                           "Jan. 1995")) +
  labs(x = "Month",
       y = "Corruption-Related Front Page Mentions") +
  theme_classic() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

## Figure 2
repubb = read_stata("repubb.dta") %>%
  ggplot(., aes(x = month_id, y = mentions)) +
  geom_line()+
  geom_point() +
  geom_vline(xintercept = 578, 
             linetype = "dashed", 
             color = "black", size = 1) +
  geom_vline(xintercept = 637, 
             linetype = "dashed", 
             color = "gray", size = 1) +
  scale_x_continuous(breaks = seq(558, 645, 3), labels = c("Jul. 2006", "Oct. 2006", 
                                                           "Jan. 2007", "Apr. 2007", "Jul. 2007", "Oct. 2007", 
                                                           "Jan. 2008", "Apr. 2008", "Jul. 2008", "Oct. 2008",
                                                           "Jan. 2009", "Apr. 2009", "Jul. 2009", "Oct. 2009",
                                                           "Jan. 2010", "Apr. 2010", "Jul. 2010", "Oct. 2010",
                                                           "Jan. 2011", "Apr. 2011", "Jul. 2011", "Oct. 2011",
                                                           "Jan. 2012", "Apr. 2012", "Jul. 2012", "Oct. 2012",
                                                           "Jan. 2013", "Apr. 2013", "Jul. 2013", "Oct. 2013")) +
  labs(x = "Month",
       y = "Corruption-Related Front Page Mentions") +
  theme_classic() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

load("dta.RData")
leg = c(`x` = "Legislature X", `xi` = "Legislature XI", `xv` = "Legislature XV", `xvi` = "Legislature XVI")

## Figure 3A
mentions_all = dta %>%
  ggplot(aes(x = la_stampa_corrupt_log)) +
  facet_wrap(leg ~ ., labeller = as_labeller(leg), scales = "free", ncol = 2) +
  geom_histogram() +
  labs(x = "log(Press Mentions)",
       y = "Count") +
  theme_classic()

## Figure 3B
mentions_corrupt = dta %>%
  filter(corrupt == 1) %>%
  ggplot(aes(x = la_stampa_corrupt_log)) +
  facet_wrap(leg ~ ., labeller = as_labeller(leg), scales = "free", ncol = 2) +
  geom_histogram() +
  labs(x = "log(Press Mentions)",
       y = "Count") +
  theme_classic() 

## Table A2
summary_stat = dta %>%
  select(-last, -first, -renominated, -corrupt, -la_stampa_base, -la_stampa_corrupt, -maj_party) %>%
  group_by(leg) %>%
  summarise_all(list(min = min, mean = mean, max = max), na.rm = TRUE)